package com.wuye.charge.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wuye.common.annotation.Log;
import com.wuye.common.core.controller.BaseController;
import com.wuye.common.core.domain.AjaxResult;
import com.wuye.common.enums.BusinessType;
import com.wuye.charge.domain.WyCost;
import com.wuye.charge.service.IWyCostService;
import com.wuye.common.utils.poi.ExcelUtil;
import com.wuye.common.core.page.TableDataInfo;

/**
 * 费用新增Controller
 *
 * @author lishuo
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/charge/cost")
public class WyCostController extends BaseController
{
    @Autowired
    private IWyCostService wyCostService;

    /**
     * 查询费用新增列表
     */
    @PreAuthorize("@ss.hasPermi('charge:cost:list')")
    @GetMapping("/list")
    public TableDataInfo list(WyCost wyCost)
    {
        startPage();
        List<WyCost> list = wyCostService.selectWyCostList(wyCost);
        return getDataTable(list);
    }

    /**
     * 导出费用新增列表
     */
    @PreAuthorize("@ss.hasPermi('charge:cost:export')")
    @Log(title = "费用新增", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WyCost wyCost)
    {
        List<WyCost> list = wyCostService.selectWyCostList(wyCost);
        ExcelUtil<WyCost> util = new ExcelUtil<WyCost>(WyCost.class);
        util.exportExcel(response, list, "费用新增数据");
    }

    /**
     * 获取费用新增详细信息
     */
    @PreAuthorize("@ss.hasPermi('charge:cost:query')")
    @GetMapping(value = "/{costId}")
    public AjaxResult getInfo(@PathVariable("costId") Long costId)
    {
        return success(wyCostService.selectWyCostByCostId(costId));
    }

    /**
     * 新增费用新增
     */
    @PreAuthorize("@ss.hasPermi('charge:cost:add')")
    @Log(title = "费用新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WyCost wyCost)
    {
        return toAjax(wyCostService.insertWyCost(wyCost));
    }

    /**
     * 修改费用新增
     */
    @PreAuthorize("@ss.hasPermi('charge:cost:edit')")
    @Log(title = "费用新增", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WyCost wyCost)
    {
        return toAjax(wyCostService.updateWyCost(wyCost));
    }

    /**
     * 删除费用新增
     */
    @PreAuthorize("@ss.hasPermi('charge:cost:remove')")
    @Log(title = "费用新增", businessType = BusinessType.DELETE)
	@DeleteMapping("/{costIds}")
    public AjaxResult remove(@PathVariable Long[] costIds)
    {
        return toAjax(wyCostService.deleteWyCostByCostIds(costIds));
    }
}
